home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CTOOLS10.ARJ / QUEUETST.C < prev    next >
C/C++ Source or Header  |  1991-12-31  |  1KB  |  62 lines

  1. /* Simple program to test the queue routines */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <time.h>
  7. #include <dos.h>
  8. #include <alloc.h>
  9. #include "queue.h"
  10.  
  11. #define    PRINT_LIST
  12.  
  13. void randstr(char *s,int length)
  14. {
  15.     int    i;
  16.  
  17.     for (i = 0; i < length; i++)
  18.         s[i] = 'a' + (char)random('z' - 'a');
  19.     s[i] = '\0';
  20. }
  21.  
  22. void main(void)
  23. {
  24.     QUEUE        *queue;
  25.     char        *s;
  26.     char        line[80];
  27.     int            i,size,length;
  28.  
  29.     printf("Size of queue to create: ");
  30.     gets(line);
  31.     size = atoi(line);
  32.     printf("Maximum length of strings: ");
  33.     gets(line);
  34.     length = atoi(line);
  35.  
  36.     printf("\nMemory at start: %lu\n",(unsigned long)coreleft());
  37.     printf("\nCreating queue of %d random strings of length %d ...\n\n",size,length);
  38.  
  39.     randomize();
  40.     queue = q_init();
  41.  
  42.     for (i = 0; i < size; i++) {
  43.         s = q_newnode(length+1);
  44.         randstr(s,random(length));
  45.         q_putright(queue,s);
  46.         printf("Adding: %s\n",s);
  47.         }
  48.  
  49.     printf("\nMemory before deleting queue: %lu\n",(unsigned long)coreleft());
  50.  
  51.     s = q_getright(queue);
  52.     while (s) {
  53.         printf("Got: %s\n",s);
  54.         q_freenode(s);
  55.         s = q_getright(queue);
  56.         }
  57.  
  58.     q_kill(queue,q_freenode);
  59.  
  60.     printf("\nMemory after deleting queue: %lu\n",(unsigned long)coreleft());
  61. }
  62.